package com.smartjobs.action;

import java.util.ArrayList;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.smartjobs.bean.CourseBean;
import com.smartjobs.bean.EducationalQualificationBean;
import com.smartjobs.bean.JobPostingVO;
import com.smartjobs.bean.JobseekerBean;
import com.smartjobs.bean.SkillMasterBean;
import com.smartjobs.bean.SkillsBean;
import com.smartjobs.bean.WorkExperienceBean;
import com.smartjobs.loader.MergeFile;
import com.smartjobs.loader.RDFLoader;
import com.smartjobs.loader.SwoopTest;
import com.smartjobs.model.ViewJSProfileModel;
import com.smartjobs.reasoner.ReasonerQuery;
import com.smartjobs.util.MyUtil;
import com.smartjobs.util.RuntimeSettings;

@SuppressWarnings("serial")
public class ViewJSProfileAction extends ActionSupport {

	JobseekerBean jobseeker;
	ArrayList<EducationalQualificationBean> educationalQualificationList;
	ArrayList<WorkExperienceBean> workExperienceList;
	ArrayList<SkillsBean> skillList;
	ArrayList<SkillMasterBean> skillMasterList;
	ArrayList<CourseBean> courseList;
	String refresh = "";
	String courseName = "";
	String cost = "";
	String noOfMonths = "";

	public String getNoOfMonths() {
		return noOfMonths;
	}

	public void setNoOfMonths(String noOfMonths) {
		this.noOfMonths = noOfMonths;
	}

	public String getCourseName() {
		return courseName;
	}

	public void setCourseName(String courseName) {
		this.courseName = courseName;
	}

	public String getCost() {
		return cost;
	}

	public void setCost(String cost) {
		this.cost = cost;
	}

	public String getRefresh() {
		return refresh;
	}

	public void setRefresh(String refresh) {
		this.refresh = refresh;
	}

	public ArrayList<CourseBean> getCourseList() {
		return courseList;
	}

	public void setCourseList(ArrayList<CourseBean> courseList) {
		this.courseList = courseList;
	}

	public ArrayList<SkillMasterBean> getSkillMasterList() {
		return skillMasterList;
	}

	public void setSkillMasterList(ArrayList<SkillMasterBean> skillMasterList) {
		this.skillMasterList = skillMasterList;
	}

	public ArrayList<SkillsBean> getSkillList() {
		return skillList;
	}

	public void setSkillList(ArrayList<SkillsBean> skillList) {
		this.skillList = skillList;
	}

	public ArrayList<WorkExperienceBean> getWorkExperienceList() {
		return workExperienceList;
	}

	public void setWorkExperienceList(
			ArrayList<WorkExperienceBean> workExperienceList) {
		this.workExperienceList = workExperienceList;
	}

	public ArrayList<EducationalQualificationBean> getEducationalQualificationList() {
		return educationalQualificationList;
	}

	public void setEducationalQualificationList(
			ArrayList<EducationalQualificationBean> educationalQualificationList) {
		this.educationalQualificationList = educationalQualificationList;
	}

	public JobseekerBean getJobseeker() {
		return jobseeker;
	}

	public void setJobseeker(JobseekerBean jobseeker) {
		this.jobseeker = jobseeker;
	}

	@SuppressWarnings("rawtypes")
	Map session = ActionContext.getContext().getSession();

	public String GetJSProfile() {
		jobseeker = new JobseekerBean();
		jobseeker.setJobSeekerID(Integer.parseInt(session.get("jobseekerID")
				.toString()));
		System.out
				.println("Inside GetJSProfile: " + jobseeker.getJobSeekerID());
		ViewJSProfileModel.GetJSProfile(jobseeker);
		return SUCCESS;
	}

	public String GetJSEQ() {
		educationalQualificationList = new ArrayList<EducationalQualificationBean>();
		int jobseekerID = (int) session.get("jobseekerID");
		ViewJSProfileModel.GetJSEQ(jobseekerID, educationalQualificationList);
		return SUCCESS;
	}

	public String GetJSWorkEx() {
		workExperienceList = new ArrayList<WorkExperienceBean>();
		int jobseekerID = (int) session.get("jobseekerID");
		ViewJSProfileModel.GetJSWorkEx(jobseekerID, workExperienceList);
		return SUCCESS;
	}

	public String GetJSSkills() {
		skillMasterList = new ArrayList<SkillMasterBean>();
		skillList = new ArrayList<SkillsBean>();
		int jobseekerID = (int) session.get("jobseekerID");
		ViewJSProfileModel.GetJSSkills(jobseekerID, skillList);
		ViewJSProfileModel.GetSkillMasterList(skillMasterList);
		return SUCCESS;
	}

	public String GetAllCourses() {
		int i;
		ArrayList<CourseBean> allCourseList = new ArrayList<CourseBean>();
		courseList = new ArrayList<CourseBean>();

		if (!refresh.equals("")) {
			System.out.println("inside refresh");
			try {
				MyUtil.saveUrl(RuntimeSettings.location + "/"
						+ RuntimeSettings.DDSFilename, RuntimeSettings.DDSUrl
						+ "/" + RuntimeSettings.DDSFilename);
			} catch (Exception ex) {
				ex.printStackTrace();
			}
			refresh = "";

			new SwoopTest().addSemantics(RuntimeSettings.location
					+ "/smartJobs.rdf");
			MergeFile.mergeFile();
		}

		// RDFLoader.loadFromDataBase();
		allCourseList = new ReasonerQuery().getAllCourses();

		for (i = 0; i < allCourseList.size(); i++) {

			if ((allCourseList.get(i).getCourseName().toLowerCase()
					.contains(courseName.toLowerCase()))
					&& (allCourseList.get(i).getCost().toLowerCase()
							.contains(cost.toLowerCase()))
					&& (allCourseList.get(i).getNoOfMonths().toLowerCase()
							.contains(noOfMonths.toLowerCase()))) {

				if (allCourseList.get(i).getSource()
						.equalsIgnoreCase("www.smartJobs.com")) {
					allCourseList.get(i).setSourceFlag(1);
					System.out.println("source: "
							+ allCourseList.get(i).getSource()
							+ " setting source flag to 1");

				} else {
					allCourseList.get(i).setSourceFlag(0);
				}

				System.out.println("source flag: "
						+ allCourseList.get(i).getSourceFlag());
				courseList.add(allCourseList.get(i));
			}
		}
		return SUCCESS;
	}
}
